<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            width: 3000px;
            height: 3000px;
        }
    </style>
</head>
<body>
    <script>
        window.onscroll = function(){
            // console.log(window.document.documentElement.scrollTop);//当DOCTYPE存在,浏览器认得他,DOCTYPE不存在,那就不认得他
            // console.log(window.document.body.scrollTop);//不认他,原因是:DOCTYPE存在,如果DOCTYPE不存在,那么浏览器就认得window.document.body.scrollTop
            var sTop = window.document.documentElement.scrollTop || window.document.body.scrollTop
            // console.log(window.document.documentElement.scrollLeft || document.body.scrollLeft);
            console.log(sTop);
        }
    </script>
</body>
</html>